# 多阶段构建 Dockerfile
FROM maven:3.8.4-openjdk-8 AS builder

WORKDIR /app
COPY ../pom.xml .
COPY admin/pom.xml admin/
COPY portal/pom.xml portal/
COPY search/pom.xml search/

# 下载依赖
RUN mvn dependency:go-offline -B

# 复制源代码并构建
COPY .. .
RUN mvn clean package -DskipTests

# 运行阶段
FROM openjdk:11-jre-slim

WORKDIR /app

# 安装curl用于健康检查
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

# 从构建阶段复制jar文件
COPY --from=builder /app/admin/target/*.jar /app/admin-app.jar
COPY --from=builder /app/portal/target/*.jar /app/portal-app.jar
COPY --from=builder /app/search/target/*.jar /app/search-app.jar

RUN mkdir -p /app/logs

EXPOSE 8080

CMD ["java", "-jar", "app.jar"]